#!/usr/local/bin/python
# Rob Dennis - Lurchington Q. Delacroix
# Keasby - TV renamer
# Project Homepage: http://code.google.com/p/keasby/

#--- Python Imports
import unittest
import logging
import os

#--- Keasby Imports
import tv_episode
from keasby_base import KeasbyError, KeasbyTestCase
from keasby_options import kopt

#--- KeasbySource Imports
from keasby_source import KeasbySource, KeasbySourceError
from keasby_source import InfoSource, InfoSourceError
from keasby_source import AvailabilitySource, AvailabilitySourceError
from tvdb_source import TvDbSource

log = logging.getLogger("keasby_logger")

class KeasbyRepo(object):
    """
    Repository searchable for new information using given information
    """
    source_subdir_name = "sources"

    def __init__(self):

        self._import_sources()

    def _import_sources(self):
        """
        initialize sources for use by KeasbyRepo
        """

        src_list = []
        src_list.append((TvDbSource, [], {}))

        self.info_sources = [src_tuple for src_tuple in src_list
                                if issubclass(src_tuple[0], InfoSource)]

        self.availability_sources = [src_tuple for src_tuple in src_list
                                       if issubclass(src_tuple[0],
                                                        AvailabilitySource)]

        log.debug("initialized %d info sources", len(self.info_sources))
        log.debug("initialized %d availability sources",
                    len(self.availability_sources))


class KeasbyRepoInternalTestCase(unittest.TestCase):
    """
    InternalTestCase for KeasbyRepo
    """

    def setUp(self):

        self.repo = KeasbyRepo()

    def test_source_import(self):

        self.repo._import_sources()

    def test_source_existence(self):

        self.assertTrue(any([self.repo.info_sources,
                                self.repo.availability_sources]))


class KeasbyRepoError(KeasbyError):
    """
    KeasbyRepo Exception
    """


if __name__ == "__main__":

    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(KeasbyRepoInternalTestCase))
    unittest.TextTestRunner(verbosity=2).run(suite)
